<?php
class TranslatorObjModel extends Model {
	
	public function saveTranslation($text, $leksId, $dictId) {
		$queryString = sprintf("
			INSERT INTO 
				`translation`(`id_leks`, `id_dict`, `value`)
			VALUES
				(%d, %d, '%s');
		", $leksId, $dictId, $text);
		return $this->_sqlInstance->query($queryString);
	}

	public function updateTranslation($text, $leksId, $dictId) {
		$queryString = sprintf("
			UPDATE
				`translation`
			SET
				`translation`.`value` = '%s'
			WHERE
				`translation`.`id_leks` = %d
			AND
				`translation`.`id_dict` = %d;
		", $text, $leksId, $dictId);
		return $this->_sqlInstance->query($queryString);
	}

	public function getTranslation($leksId, $dictId) {
		$queryString = sprintf("
			SELECT
				`translation`.`value`
			FROM
				`translation`
			WHERE
				`translation`.`id_leks` = %d
			AND
				`translation`.`id_dict` = %d;
		",$leksId, $dictId);
		$result = $this->_sqlInstance->query($queryString);
		if(!empty($result)) {
			return $result[0]->value;
		}
		return '';
	}
	
	public function getOriginal($leksId) {
		$queryString = sprintf("
			SELECT
				`base`.`value`
			FROM
				`base`
			WHERE
				`base`.`id_leks` = %d
		",$leksId);
		$result = $this->_sqlInstance->query($queryString);
		return $result[0]->value;
	}
}